package cn.neusoft.service.impl;

import cn.neusoft.po.Product;
import cn.neusoft.mapper.ProductMapper;
import cn.neusoft.query.ProductQuery;
import cn.neusoft.service.IProductService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hxj
 * @since 2023-12-22
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Override
    public Page<Product> getByPage(ProductQuery query) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(StringUtils.hasText(query.getName()),"name",query.getName());
        queryWrapper.orderByDesc("id");
        //存放分页条件
        Page pageQuery = new Page(query.getCurrent(), query.getSize());

        //自定义分页时  准备好分页条件Page  准备好搜索条件Wrapper
        Page<Product> departmentIPage = baseMapper.selectJoin(pageQuery, queryWrapper);
        return departmentIPage;
    }
}
